import pyautogui
import pyautogui as pag
from utils.kmlkeymouse import *


def mouseClick(image, confidence=0.99):
    coor = pyautogui.locateCenterOnScreen(image, confidence=confidence)
    if coor is not None:
        pyautogui.click(coor.x, coor.y, clicks=1, interval=0.2, duration=0.2, button='left')
        return True
    return False


def get_position():
    # 获取当前鼠标的位置
    x, y = pag.position()  # 返回鼠标的坐标
    # posStr = "Position（x，y）:" + str(x).rjust(4) + ',' + str(y).rjust(4)
    return int(str(x).rjust(4)), int(str(y).rjust(4))  # 打印坐标


def up(x, y):
    y = y - 10
    role_move_coor(x, y)


def down(x, y):
    y = y + 10
    role_move_coor(x, y)


def left(x, y):
    x = x - 10
    role_move_coor(x, y)


def right(x, y):
    x = x + 10
    role_move_coor(x, y)


def role_move_coor(x, y):
    # 将鼠标运动到指定位置并且右击
    # move_rel(x, y)
    move_to(x, y)
    right_button_down()
    right_button_up()


def keydownup(key="b"):
    # 按下按钮key
    key_down(key)
    key_up(key)
